package com.stylefeng.guns.core.util;

import java.util.ArrayList;
import java.util.List;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.modular.system.model.CarryBasicInformation;
import com.stylefeng.guns.modular.system.service.ICarryBasicInformationService;

/**
 * 车次的生成号
 * @author Administrator
 *
 */
public class InitCarNumberID {
	

	private static InitCarNumberID instance  = new InitCarNumberID();
	
	private static int id;
	
		//获取唯一可用的对象
	   public static InitCarNumberID getInstance(ICarryBasicInformationService carryBasicInformationService){
		  if(id==0){
			  EntityWrapper<CarryBasicInformation> entityWrapper = new EntityWrapper<>();
			  List<String> strs = new ArrayList<>();
			 strs.add("carry_number");
			  Wrapper<CarryBasicInformation> wrapper = entityWrapper.orderDesc(strs);
			  int strID;
			  if(carryBasicInformationService.selectList(wrapper).size()==0){
				  strID =0;
			  }else{
				  strID = carryBasicInformationService.selectList(wrapper).get(0).getCarryNumber();
			  }
			 id = strID;
			 id++;
		  }else{
			  id++;
		  }
	      return instance;
	   }
	   
	private InitCarNumberID(){}
	
	//生成
	public  String initDisorderID(){
		return  id+"";
	}
}
